<template>
    <div>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-select size="small" v-model="statusVal" placeholder="请选择审核状态">
            <el-option v-for="item in statuslist" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input clearable placeholder="请输入订单号" size="small" v-model="searchList.searchValue"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker size="small" v-model="searchList.timelist" type="daterange" align="right" unlink-panels range-separator="至"
                          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="init">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="tableData" style="width: 100%" header-align="center">
        <el-table-column type="index" label="序号" width="" align="center"></el-table-column>
        <el-table-column prop="task_order" label="订单编号" align="center"></el-table-column>
        <el-table-column prop="task_shopname" label="店铺名" align="center"></el-table-column>
        <el-table-column prop="brushhands_tbname" label="刷手会员号" width="" align="center"></el-table-column>
        <el-table-column prop="baby_id" label="宝贝ID" width="" align="center"></el-table-column>
        <el-table-column prop="task_bjmoney" label="商品金额" width="" align="center"></el-table-column>
        <el-table-column prop="imgs" label="评价截图" width="" align="center">
           <template slot-scope="scope">
             <a :href="scope.row.imgs" target="_blank">
               <img :src="scope.row.imgs" style="width:100px;height:100px;" alt="">
             </a>
           </template>
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" align="center"></el-table-column>
        <el-table-column fixed="right" label="审核" width="" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.pj_status == 3">
              <el-button @click="onPass(scope.row,1)" type="primary" plain size="mini">通过</el-button>
              <el-button @click="onPass(scope.row,2)" size="mini" type="danger" plain>拒绝</el-button>
            </div>
            <el-button v-if="scope.row.pj_status == 2" type="success" size="mini" plain disabled>已通过</el-button>
            <el-button v-if="scope.row.status == 4" type="info" size="mini" plain disabled>已拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :page-size="20" :current-page="searchList.pn" layout="total,prev, pager, next"
                     :total="searchList.total" @current-change="pnChange">
      </el-pagination>
    </div>
</template>

<script>
  import { audit_evaluatelist,userinfo,audit_evaluateconfirm,audit_evaluaterefuse } from '../../api/api'
  export default {
    name: "AdminRefundList",
    data(){
      return{
        tableData: [],
        searchList: {
          searchValue: "",
          timelist:[],
          pn: 1,
          total: 0
        },
        loading:false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        statusVal:0,
        statuslist: [
          {
            value: 0,
            label: '全部'
          },
          {
            value: 1,
            label: '等待审核'
          }, {
            value: 2,
            label: '审核通过'
          }, {
            value: 3,
            label: '拒绝审核'
          }],
      }
    },
    mounted(){
      let params = {
        page:this.searchList.pn,
        page_size:20,
      }
      this.getorderList(params)
    },
    methods:{
      //获取用户信息
      getUser(){
        userinfo().then(res=>{
          console.log('个人信息',res)
          if(res.Status == 200){
            this.$emit('getMoney',res.Data.money)
          }else{
            this.$message.error(res.Message)
          }
        })
      },
      pnChange(pn) {
        this.searchList.pn = pn
        let params = {
          order:this.searchList.searchValue,
          time:this.searchList.timelist,
          page:pn,
          page_size:20,
          status:this.statusVal
        }
        this.getorderList(params)
      },
      //获取订单列表
      getorderList(params){
        audit_evaluatelist(params).then(res=>{
          if(res.Status == 200){
            this.tableData = res.Data
            this.searchList.total = res.Count
            let ipos
            this.tableData.forEach(item => {
              ipos = item.create_time.indexOf("+")
              item.create_time = item.create_time.replace(/T/g," ").substring(0,ipos)
            })
          }else{
            this.$message.error(res.Message)
          }
        })
      },
      //查询
      init(){
        if(this.searchList.timelist.length>0){
          this.searchList.timelist[0] = this.searchList.timelist[0] + '00:00:00'
          this.searchList.timelist[1] = this.searchList.timelist[1] + '23:59:59'
        }
        let params = {
          order:this.searchList.searchValue,
          time:this.searchList.timelist,
          page:this.searchList.pn,
          page_size:20,
          status:this.statusVal
        }
        this.getorderList(params)
      },
      //通过
      onPass(row,idx){
        console.log('row',row)
        let params = {
          ce_id:row.ce_id,
          task_id:row.id,
        }
        if(idx === 1){
          audit_evaluateconfirm(params).then(res=>{
            console.log('成功',res)
            if(res.Status == 200){
              this.$message({
                type: '通过审核',
                message: res.Message
              });
              this.init()
            }else{
              this.$message({
                type: 'error',
                message: res.Message
              });
            }
          })
        }else{
          this.open(params)
        }
      },
      open(params) {
        this.$prompt('请输入拒绝原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          params.note = value
          audit_evaluaterefuse(params).then(res=>{
            console.log('拒绝',res)
            if(res.Status == 200){
              this.$message({
                type: '拒绝审核',
                message: res.Message
              });
              this.init()
            }else{
              this.$message({
                type: 'error',
                message: res.Message
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });
        });
      }
    }
  }
</script>

<style scoped>

</style>
